﻿#region Using Directives

    using System;
    using System.Linq;

    using Csla;

    using MarketPulse.BusinessLogic.Core;
    using MarketPulse.Reporting.Core.Criteria;

#endregion

namespace MarketPulse.Reporting.Core
{
    /// <summary>
    /// This class represents a collection of Reporting Branches
    /// </summary>
    [Serializable]
    [Csla.Server.ObjectFactory("MarketPulse.DataAccess.Factory.ReportingBranchFactory, MarketPulse.DataAccess.Factory", "FetchInfoList")]
    public class ReportingBranchInfoList : MarketPulseReadOnlyListBase<ReportingBranchInfoList, ReportingBranchInfo>
    {        

        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private ReportingBranchInfoList()
            {
            }

        #endregion

        #region Methods

            #region Factory Methods

                /// <summary>
                /// Method used to get a read only list of read only ReportingBranches that are associated with a particular Client (via the DataPortal client proxy)
                /// </summary>
                /// <param name="clientGUID">The GUID of the Client used to retrieve the list</param>
                /// <returns>A populated read only list of read only ReportingBranches</returns>
                public static ReportingBranchInfoList GetByClientGUID(Guid clientGUID)
                {
                    return DataPortal.Fetch<ReportingBranchInfoList>(new SingleCriteria<Guid>(clientGUID));
                }

                /// <summary>
                /// Method used to get a read only list of read only ReportingBranches that are associated with a particular Client for the profileGuid supplied (via the DataPortal client proxy)
                /// </summary>
                /// <param name="profileGuid">The Guid of the Profile used to retrieve the list</param>
                /// <param name="clientGuid">The Guid of the Client used to retrieve the list</param>
                /// <returns>A populated read only list of read only ReportingBranches</returns>
                public static ReportingBranchInfoList GetByProfileGUIDClientGUID(Guid profileGuid, Guid clientGuid)
                {
                    return DataPortal.Fetch<ReportingBranchInfoList>(new ClientGUIDAndProfileGUIDCriteria(clientGuid, profileGuid));
                }

                /// <summary>
                /// Method used to get a read only list of read only ReportingBranches that are associated with a particular Client and Profile (via the DataPortal client proxy)
                /// </summary>
                /// <param name="clientGUID">The GUID of the Client used to retrieve the list</param>
                /// <param name="profileGUID">The GUID of the Profile used to retrieve the list</param>
                /// <param name="reportingPeriod">The ReportingPeriodInfo object used to retrieve the list</param>
                /// <param name="reportingLevels">The ReportingLevelInfoList object used to filter the list</param>
                /// <returns>A populated read only list of read only ReportingBranches</returns>
                public static ReportingBranchInfoList GetByClientGUIDandProfileGUIDAndReportingPeriodAndReportingLevels(Guid clientGUID, Guid profileGUID, ReportingPeriodInfo reportingPeriod, ReportingLevelInfoList reportingLevels)
                {
                    return DataPortal.Fetch<ReportingBranchInfoList>(new ClientGUIDAndProfileGUIDAndReportingPeriodAndReportingLevelsCriteria(clientGUID, profileGUID, reportingPeriod, reportingLevels));
                }

                // TODO: Refactor this to retrieve on something more extendable.
                /// <summary>
                /// Method used to get a read only list of read only ReportingBranches that are associated with this particular Client and Country as well as populate the results data.
                /// </summary>
                /// <param name="clientGUID">The GUID of the Client used to retrieve this list.</param>
                /// <param name="countryGUID">The GUID of the Country used to retrieve this list.</param>
                /// <param name="language">The language identifier (ie. en or fr) to use when localising text from the database.</param>
                /// <param name="currentStartDateTime">The start date of the reporting period.</param>
                /// <param name="currentEndDateTime">The end date of the reporting period.</param>
                /// <param name="dataStartDateTime">The start date of when to retrieve data.</param>
                /// <param name="dataEndDateTime">The end date of when to retrieve data.</param>
                /// <returns>A populated read only list of read only ReportingBranches</returns>
                public static ReportingBranchInfoList GetByClientGUIDAndCountryGUID(Guid clientGUID, Guid countryGUID, string language, DateTime currentStartDateTime, DateTime currentEndDateTime, DateTime dataStartDateTime, DateTime dataEndDateTime)
                {
                    return DataPortal.Fetch<ReportingBranchInfoList>(new ClientGUIDAndCountryGUIDAndResultsDateRangeCriteria(clientGUID, countryGUID, language, currentStartDateTime, currentEndDateTime, dataStartDateTime, dataEndDateTime));
                }

            #endregion

        #endregion

        #region Properties

            /// <summary>
            /// Get a ReportingBranchInfo object by the BranchGUID property.
            /// </summary>
            /// <param name="displayName">The GUID of the Branch to retrieve.</param>
            /// <returns>A ReportingBranchInfo object.</returns>
            public ReportingBranchInfo this[Guid branchGUID]
            {
                get
                {
                    return this.Where(b => b.GUID.Value.Equals(branchGUID)).FirstOrDefault();
                }
            }

        #endregion
    }
}
